const FileManagerPlugin = require('filemanager-webpack-plugin')
const toDate = new Date()
const year = toDate.getFullYear()
const month =
  toDate.getMonth() + 1 > 10
    ? toDate.getMonth() + 1
    : '0' + (toDate.getMonth() + 1)
const date = toDate.getDate() > 10 ? toDate.getDate() : '0' + toDate.getDate()
const hours =
  toDate.getHours() > 10 ? toDate.getHours() : '0' + toDate.getHours()
const minutes =
  toDate.getMinutes() > 10 ? toDate.getMinutes() : '0' + toDate.getMinutes()
const dateName = year + '_' + month + '_' + date + '_' + hours + minutes + '_'

module.exports = {
  chainWebpack: (config) => {
    // 移除 prefetch 插件
    config.plugins.delete('preload')
    config.plugins.delete('prefetch')
  },
  productionSourceMap: false,
  devServer: {
    port: 8080,
  },
  configureWebpack: (config) => {
    if (process.env.USE_CDN == 1) {
      config.plugins.push(
        new FileManagerPlugin({
          onEnd: {
            //首先需要删除项目根目录下的.zip
            delete: ['./*.zip'],
            //然后我们选择dist文件夹将之打包成zip并放在根目录
            archive: [
              {
                source: './dist',
                destination: './' + dateName + 'm_manager.zip',
              },
            ],
          },
        })
      )
    }
    config.externals = {
      vue: 'Vue',
      vuex: 'Vuex',
      'vue-router': 'VueRouter',
      axios: 'axios',
      vconsole: 'vconsole',
    }
  },
}
